{include file="public/header" /}
</head>
<body>
<div class="wrap js-check-wrap">
    <form class="form-horizontal js-ajax-form" method="post" action="{:url('Finance/withdraw')}">
        <div class="well form-inline margin-top-20">
            所属用户:
            <input type="text" class="form-control" name="userName" style="width: 200px;"
                   value="{$params['userName']|default=''}" placeholder="请输入手机号或者邮箱地址">　
            订单号:
            <input type="text" class="form-control" name="orderNo" style="width: 200px;"
                   value="{$params['orderNo']|default=''}" placeholder="请输入名称">　
            转账户名:
            <input type="text" class="form-control" name="accountName" style="width: 200px;"
                   value="{$params['accountName']|default=''}" placeholder="请输入名称">　
            <input type="submit" class="btn btn-primary" value="搜索"/>　
            <a class="btn btn-danger" href="{:url('Finance/withdraw')}">清空</a>
        </div>

        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th>ID</th>
                <th>订单号</th>
                <th>用户名</th>
                <th>提现金额</th>
                <th>冻结ID</th>
                <th>状态</th>
                <th>操作人</th>
                <th>备注</th>
                <th>确认时间</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            {foreach name="list" item="vo"}
            <tr>
                <td>{$vo.withdrawId}</td>
                <td>{$vo.orderNo}</td>
                <td>{$vo.userName}</td>
                <td>{$vo.amount}</td>
                <td>{$vo.freezeId}</td>
                <td>
                    {switch $vo.status }
                        {case 0}
                            未处理
                        {/case}
                        {case 1}
                            <span class="color-red">订单已锁定</span>
                        {/case}
                        {case 2}
                            <span class="color-green">提现成功</span>
                        {/case}
                        {case 3}
                            <span class="color-red">提现失败</span>
                        {/case}
                    {/switch}
                </td>
                <td>{$vo.memberName}</td>
                <td>{$vo.remark}</td>
                <td>{$vo.modifyTime}</td>
                <td>{$vo.createTime}</td>
                <td>
                    {switch $vo.status }
                        {case 0}
                            <a href="javascript:void(0)" class="js-locking" data-id="{$vo.withdrawId}">锁定</a>　　
                        {/case}
                        {case 1}
                            <a href="javascript:void(0)" class="js-confirm" data-id="{$vo.withdrawId}">确认</a>　　
                            <a href="javascript:void(0)" class="js-refuse"  data-id="{$vo.withdrawId}">拒绝</a>
                        {/case}
                        {case 2}
                            <span class="color-green">已允许</span>
                        {/case}
                        {case 3}
                            <span class="color-red">已拒绝</span>
                        {/case}
                    {/switch}

                </td>
            </tr>
            {/foreach}
        </table>
        {:$pagination}
    </form>
</div>
<script src="{$static}js/admin.js"></script>
<script src="{$static}js/layer/layer.js"></script>
<script type="text/javascript">
    $('.js-locking').click(function () {
        var id = $(this).data('id');
        $.ajax({
            url: "{:url('Finance/withdrawLocking')}",
            type: "POST",
            data: {id: id},
            dataType: 'json',
            async: false,
            success: function (res) {
                if(res.errorCode === 200){
                    window.location.reload();
                }else{
                    layer.alert(res.message, {
                        title: '提示',
                        icon: 2
                    });
                }
            }
        });
    });

    $('.js-confirm').click(function () {
        var id = $(this).data('id');

        layer.confirm('您确认该订单是否已转账', {
            btn:['确认','取消'],
            success:function(){
                this.enterEsc = function (event) {
                    if (event.keyCode === 13) {
                        $(".layui-layer-btn0").click();
                        return false;
                    }
                };
                $(document).on('keydown', this.enterEsc);

                $(".layui-layer-btn0").on("click",function() {
                    $.ajax({
                        url: "{:url('Finance/withdrawConfirm')}",
                        type: "POST",
                        data: {id: id},
                        dataType: 'json',
                        async: false,
                        success: function (res) {
                            if(res.errorCode === 200){
                                window.location.reload();
                            }else{
                                layer.alert(res.message, {
                                    title: '提示',
                                    icon: 2
                                });
                            }
                        }
                    });
                    return false
                })
            },
            end:function(){
                $(document).off('keydown',this.enterEsc);
            }
        });
    });

    $('.js-refuse').click(function () {
        var id = $(this).data('id');
        $.ajax({
            url: "{:url('Finance/withdrawRefuse')}",
            type: "POST",
            data: {id: id},
            dataType: 'json',
            async: false,
            success: function (res) {
                if(res.errorCode === 200){
                    window.location.reload();
                }else{
                    layer.alert(res.message, {
                        title: '提示',
                        icon: 2
                    });
                }
            }
        });
    });
</script>
</body>
</html>